// model/User.java
package main.java.com.cinema.model;

import main.java.com.cinema.util.MD5Util;

import java.io.Serializable;
import java.time.LocalDateTime;

public class User implements Serializable {
    private static final long serialVersionUID = 1L;

    public enum Role {
        ADMIN, MANAGER, STAFF
    }

    private String userId;
    private String username;
    private String password;  // 存储MD5加密后的密码
    private Role role;
    private String phoneNumber;
    private LocalDateTime registrationTime;
    private boolean passwordChanged;

    // 构造函数
    public User() {}

    public User(String userId, String username, String password, Role role, String phoneNumber) {
        this.userId = userId;
        this.username = username;
        this.password = MD5Util.encrypt(password);  // 使用MD5加密存储密码
        this.role = role;
        this.phoneNumber = phoneNumber;
        this.registrationTime = LocalDateTime.now();
        this.passwordChanged = true; // 默认已修改密码
    }

    // Getters and Setters
    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = MD5Util.encrypt(password);  // 使用MD5加密存储密码
    }

    // 直接设置加密密码的方法（用于从文件读取）
    public void setEncryptedPassword(String encryptedPassword) {
        this.password = encryptedPassword;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public LocalDateTime getRegistrationTime() {
        return registrationTime;
    }

    public void setRegistrationTime(LocalDateTime registrationTime) {
        this.registrationTime = registrationTime;
    }

    public boolean isPasswordChanged() {
        return passwordChanged;
    }

    public void setPasswordChanged(boolean passwordChanged) {
        this.passwordChanged = passwordChanged;
    }

    // 验证密码方法
    public boolean verifyPassword(String inputPassword) {
        return this.password.equals(MD5Util.encrypt(inputPassword));
    }
}
